package com.trade.tradebusiness.trade.order;


import com.trade.core.exception.TradeBaseException;
import com.trade.core.message.TradeObjectRestResponse;
import com.trade.core.trade.TradeProcessorStepAbstract;
import com.trade.tradebusiness.entity.dto.TradeCreateOrderDbDTO;
import com.trade.tradebusiness.entity.vo.TradeCreateOrderDbVO;
import com.trade.tradebusiness.enums.OrderTradeProcessorStepEnums;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author sven.wang
 * @version 2022/1/6 15:26
 * @Description: 下单入库操作
 */
@Service
@Slf4j
public class CreateOrderDbTradeStep extends TradeProcessorStepAbstract<TradeCreateOrderDbDTO,TradeCreateOrderDbVO> {

    @Override
    public String step() {
        return OrderTradeProcessorStepEnums.ORDER_DB.name();
    }


    @Override
    public void checkParam(TradeCreateOrderDbDTO param) {

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public TradeObjectRestResponse<TradeCreateOrderDbVO> doProcess(TradeCreateOrderDbDTO param) {

        TradeCreateOrderDbVO vo = new TradeCreateOrderDbVO();
        vo.setOrderId("00000000001");
        return TradeObjectRestResponse.success(vo);
    }

    @Override
    public void checkOutParam(TradeCreateOrderDbVO outParam) {
        if(StringUtils.isBlank(outParam.getOrderId())){
            throw new TradeBaseException("步骤返回数据异常: 订单id不存在");
        }
    }


}
